//
//  DSSHLingTaskDetailOfWaitForLingVC.m
//  DSSH
//
//  Created by lcy on 16/4/15.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHLingTaskDetailOfWaitForLingVC.h"
#import "UIView+Round.h"
#import "LingTaskDetailCell1.h"
#import "DSSHQiangRelatedTaskVC.h"
#import "DSSHTaskPointDistributeVC.h"
#import "DSSHTaskQiangSettingVC.h"
@interface DSSHLingTaskDetailOfWaitForLingVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView*detailTableView;

@end

@implementation DSSHLingTaskDetailOfWaitForLingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    [self setupConstraints];
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData
{
    self.title = @"任务详情";
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    
    UIBarButtonItem * rightBarBtn = [[UIBarButtonItem alloc]initWithTitle:@"待领取" style:UIBarButtonItemStylePlain target:self action:@selector(clickRightBarBtn)];
    self.navigationItem.rightBarButtonItem = rightBarBtn;
    //添加详情表
    self.detailTableView =[[ UITableView alloc]initWithFrame:CGRectMake(5, 69, ZYAppWidth-10, ZYAppHeight-69) style:UITableViewStyleGrouped];
    self.detailTableView.delegate = self;
    self.detailTableView.dataSource = self;
    [self.detailTableView getRoundView:5];
    self.detailTableView.layer.borderWidth = 1;
    self.detailTableView.layer.borderColor = [[UIColor grayColor]CGColor];
    
    [self.view addSubview:self.detailTableView];
    
    
}
-(void)setupConstraints
{
    
}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma 点击右边的待抢单按钮
-(void)clickRightBarBtn
{
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 3;
    }else
    {
        return 2;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.00001;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 1)
    {
        LingTaskDetailCell1 * cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[NSBundle mainBundle]loadNibNamed:@"LingTaskDetailCell1" owner:nil options:nil][0];
        }
        return cell;
    }else
    {
        UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
        }
        if (indexPath.section == 0 )
        {
            if (indexPath.row == 0)
            {
                cell.contentView.backgroundColor = COLOR_NAVIGATE_BAR;
                cell.textLabel.text = @"项目名称：未来之光";
                cell.textLabel.font = FONT(16);
                cell.textLabel.textAlignment = NSTextAlignmentCenter;
                cell.textLabel.textColor = [UIColor whiteColor];
            }
            if (indexPath.row == 2)
            {
                UIButton * qiangbtn = [UIButton new];
                [qiangbtn setImage:[UIImage imageNamed:@"ling"] forState:UIControlStateNormal];
                [qiangbtn addTarget:self action:@selector(clickQiangZiBtn) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:qiangbtn];
                
                UIButton * relatedBtn = [UIButton new];
                [relatedBtn setTitle:@"关联任务" forState:UIControlStateNormal];
                [relatedBtn addTarget:self action:@selector(clickRelatedBtn) forControlEvents:UIControlEventTouchUpInside];
                relatedBtn.titleLabel.font = FONT(13);
                [relatedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [cell.contentView addSubview:relatedBtn];
                
                relatedBtn.layer.borderWidth = 1;
                relatedBtn.layer.borderColor = [[UIColor grayColor]CGColor];
                [relatedBtn getRoundView:5];
                
                UIButton * pointBtn = [UIButton new];
                [pointBtn setTitle:@"点位分布" forState:UIControlStateNormal];
                pointBtn.titleLabel.font = FONT(13);
                [pointBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [pointBtn addTarget:self action:@selector(clickPointBtn) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:pointBtn];
                
                pointBtn.layer.borderWidth = 1;
                pointBtn.layer.borderColor = [[UIColor grayColor]CGColor];
                [pointBtn getRoundView:5];
                
                UIButton * cancelBtn = [UIButton new];
                [cancelBtn setTitle:@"放弃" forState:UIControlStateNormal];
                cancelBtn.titleLabel.font = FONT(13);
                [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [cancelBtn addTarget:self action:@selector(clickPointBtn) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:cancelBtn];
                
                cancelBtn.layer.borderWidth = 1;
                cancelBtn.layer.borderColor = [[UIColor grayColor]CGColor];
                [cancelBtn getRoundView:5];
                [qiangbtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerX.equalTo(cell.contentView.mas_centerX);
                    make.size.mas_equalTo(CGSizeMake(73*WIDTH_SCALE, 73*WIDTH_SCALE));
                    make.top.equalTo(cell.contentView.mas_top).with.offset(10*HIGHT_SCALE);
                }];
                [relatedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(cell.contentView.mas_left).with.offset(15*WIDTH_SCALE);
                    make.size.mas_equalTo(CGSizeMake(90*WIDTH_SCALE, 30*HIGHT_SCALE));
                    make.bottom.equalTo(cell.contentView.mas_bottom).with.offset(-15*HIGHT_SCALE);
                }];
                [pointBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.equalTo(cell.contentView.mas_right).with.offset(-15*WIDTH_SCALE);
                    make.size.mas_equalTo(CGSizeMake(90*WIDTH_SCALE, 30*HIGHT_SCALE));
                    make.bottom.equalTo(cell.contentView.mas_bottom).with.offset(-15*HIGHT_SCALE);
                }];
                [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerX.mas_equalTo(cell.contentView.mas_centerX);
                    make.size.mas_equalTo(CGSizeMake(90*WIDTH_SCALE, 30*HIGHT_SCALE));
                    make.bottom.equalTo(cell.contentView.mas_bottom).with.offset(-15*HIGHT_SCALE);
                }];

                
            }
        }
        if (indexPath.section == 1)
        {
            if (indexPath.row == 0)
            {
                UILabel * sumLabel = [UILabel new];
                sumLabel.text = @"共10个任务";
                sumLabel.font = FONT(13);
                [cell.contentView addSubview:sumLabel];
                
                UILabel * hejiLabel = [UILabel new];
                hejiLabel.text = @"合计：";
                hejiLabel.font = FONT(13);
                [cell.contentView addSubview:hejiLabel];
                
                UILabel * moneyLabel = [UILabel new];
                moneyLabel.text = @"$18.4元";
                moneyLabel.font = FONT(13);
                moneyLabel.textColor = [UIColor redColor];
                [cell.contentView addSubview:moneyLabel];
                
                [sumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(cell.contentView.mas_left).with.offset(15*WIDTH_SCALE);
                    make.size.mas_equalTo(CGSizeMake(80*WIDTH_SCALE, 30*HIGHT_SCALE));
                    make.top.equalTo(cell.contentView.mas_top).with.offset(7*HIGHT_SCALE);
                }];
                
                [hejiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(sumLabel.mas_right).with.offset(20*WIDTH_SCALE);
                    make.size.mas_equalTo(CGSizeMake(50*WIDTH_SCALE, 30*HIGHT_SCALE));
                    make.top.equalTo(cell.contentView.mas_top).with.offset(7*HIGHT_SCALE);
                }];
                [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(hejiLabel.mas_right).with.offset(10*WIDTH_SCALE);
                    make.right.equalTo(cell.contentView.mas_right).with.offset(-20*WIDTH_SCALE);
                    make.height.mas_equalTo(30*HIGHT_SCALE);
                    make.top.equalTo(cell.contentView.mas_top).with.offset(7*HIGHT_SCALE);
                }];
            }else
            {
                cell.textLabel.text = @"抢单倒计时：20：00分钟";
                cell.textLabel.font = FONT(13);
            }
        }
        return cell;
        
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 1)
    {
        return 270;
    }
    if (indexPath.section == 0 && indexPath.row == 2)
    {
        return 170*HIGHT_SCALE;
    }
    else
    {
        return 44;
    }
}
-(void)clickQiangZiBtn
{
    DSSHTaskQiangSettingVC * VC = [[DSSHTaskQiangSettingVC alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}
#pragma 点击关联任务
-(void)clickRelatedBtn
{
    DSSHQiangRelatedTaskVC * taskVC = [[DSSHQiangRelatedTaskVC alloc]init];
    [self.navigationController pushViewController:taskVC animated:YES];
}
#pragma 点击点位分布
-(void)clickPointBtn
{
    DSSHTaskPointDistributeVC * taskVC = [[DSSHTaskPointDistributeVC alloc]init];
    [self.navigationController pushViewController:taskVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
